#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

int main(int argc, char *argv[])
{
    unsigned long int pointsIn = 0;
    unsigned long int pointsTotal = 0;
    float px=0, py=0, aux =0, aux2 =0;
    float PI;
    int i;
    time_t inicio;

    srand((unsigned)time(NULL));
    
    inicio = time(0);
    for (i = 0; i <= 100000000; i++)
    {
          px = 2;
          py = 2;     
          while ((px<0) || (px>1))
                px = (float)rand()/rand();
          while ((py<0) || (py>1))
                py = (float)rand()/rand();

          pointsTotal++;
          
          px = px*px;
          py = py*py;
          
          aux = px + py;

          aux2 = sqrt(aux);

          if ( aux2 <= 1 )
             pointsIn++;
//    printf("%d \n", i);             
//    printf("%d %d\n", pointsIn, pointsTotal);
    }
    
    PI = (float)4*pointsIn/pointsTotal;
                            // PI = pointsIn/pointsTotal
    
    printf("Tempo: %d\n", time(0)-inicio);
    printf("%d %d\n", pointsIn, pointsTotal);
    printf("PI = %.20f\n", PI);    
	return 0;    
}
